<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
    <title>导入用户</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet"
          href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <script type="text/javascript"
            src="${pageContext.request.contextPath}/js/jquery-form.js"></script>
    <script type="text/javascript">


        //导入excel
        function exceltodata() {
            if ($('#photoCover').val() == "") {
                alert("请先选择文件");
                return false;
            }

            var excelname = /^.*\.xlsx$|^.*\.xls$/;
            if (excelname.test($('#photoCover').val())) {
                //表单提交
                $("#tf").ajaxSubmit();
                alert("导入成功");
                //表单提交的第二张方式


            } else {
                alert("请选择正确的excel文件格式(支持.xlsx或者.xls)");
            }
        }
    </script>

</head>
<body>


<%-- <form action="${pageContext.request.contextPath}/user/fileUpload" method="post" --%>
<form action="${pageContext.request.contextPath}/excel/fileUpload" method="post"
      enctype="multipart/form-data" id="tf">
    <input id="lefile" type="file" style="display:none" name="file">
    <div class="input-append" style="position:absolute;;left:1200px;">
        <input id="photoCover" class="input-large" type="text"
               readonly="true" style="height:30px;"> <a
            class="btn btn-primary" onclick="$('input[id=lefile]').click();">选择表</a>
        <a class="btn btn-primary" onclick="exceltodata()">导入</a>
    </div>
</form>
<script type="text/javascript">
    $('input[id=lefile]').change(function() {
        $('#photoCover').val($(this).val());
    });
</script>
</body>
</html>
